/*
 *   Copyright (C) 2009  Jens Kieselbach
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You may obtain a copy of the License at http://www.gnu.org/licenses/gpl.html
 */
package de.kieselbach.swing

import com.jgoodies.looks.*
import com.jgoodies.looks.plastic.*
import groovy.swing.*
import groovy.swing.factory.*

public class ExtendedSwingBuilder extends SwingBuilder {

    public ExtendedSwingBuilder(boolean init = true) {
        super(init)
    }

    @Override
    def registerActionButtonWidgets() {

        super.registerActionButtonWidgets()
        registerFactory("processableButton", new RichActionWidgetFactory(ProcessableButton))
        registerFactory("flatButton", new RichActionWidgetFactory(FlatButton))
    }

    @Override
    protected Object createNode(Object name, Map attributes, Object value) {

        if(name == 'button' || name == 'processableButton' || name == 'flatButton') {

            def validator = null
            def activator = null

            if(attributes != null) {

                validator = attributes['validator']
                if(validator != null) {
                    attributes.remove('validator')
                }

                activator = attributes['activator']
                if(activator != null) {
                    attributes.remove('activator')
                }
            }

            def node = super.createNode(name, attributes, value)

            if(validator != null) {
                validator.enable(node)
            }

            if(activator != null) {
                activator.add(node)
            }

            node
        }
		else if(name == 'buttonBar') {
			
			def node = super.createNode('toolBar', attributes, value)
			
			node.putClientProperty(PlasticLookAndFeel.BORDER_STYLE_KEY, BorderStyle.EMPTY);
			node.rollover = true
			node.floatable = false
			
			node
		}
        else {
            super.createNode(name, attributes, value)
        }
    }
}